using UnityEngine;
using System.Collections;

public class EnemyWaitState : State<EnemyControl>
{
    #region Singleton

    private static EnemyWaitState instance = new EnemyWaitState();
    public static EnemyWaitState Instance { get { return instance; } }
    private EnemyWaitState() { }

    #endregion

    #region State

    public override void OnEnterState(EnemyControl behaviour)
    {
    }

    public override void OnUpdateState(EnemyControl behaviour)
    {
        if (!behaviour.IsTargetInViewRange())
            behaviour.State = EnemyAlertState.Instance;
        else if (!behaviour.IsObstacleInDetectionRange())
            behaviour.State = EnemyHuntState.Instance;
        else if (behaviour.waitTimeWaitWalkBackwards < Time.timeSinceLevelLoad)
            behaviour.moveDirection = -behaviour.transform.forward * behaviour.walkBackwardsSpeed;

        behaviour.Move();
    }

    public override void OnFixedUpdateState(EnemyControl behaviour)
    {
    }

    public override void OnExitState(EnemyControl behaviour)
    {
        behaviour.moveDirection = Vector3.zero;
    }

    public override void OnCollisionState(EnemyControl behaviour, Collision other)
    {
        behaviour.waitTimeEndAction = Time.timeSinceLevelLoad + behaviour.waitTimeWaitWalkBackwards;
    }

    public override void OnTriggerState(EnemyControl behaviour, Collider other)
    {
    }

    #endregion
}
